package com.kede.api.stand.controller;

import com.kede.api.ienum.AppIdTypeEnum;
import com.kede.api.stand.service.LoginService;
import com.kede.pojo.ResHttp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 独立服务
 *
 * @author 11856
 * @date 2023/06/12
 */
@RestController
@RequestMapping("user")
public class LoginsController {

    @Resource
    private LoginService loginService;


    /**
     * 用户小程序端获取用户微信绑定的手机号
     * @param code
     * @param appIdType
     * @return
     */
    @GetMapping("getWxPhone")
    public ResHttp getWxphone(String code, String appIdType){
        AppIdTypeEnum appIdTypeEnum = AppIdTypeEnum.valueOfCode(appIdType);
        String wxPhone = loginService.getWxPhone(code, appIdTypeEnum);
        return ResHttp.okData(wxPhone);
    }

    /**
     * 用户小程序端通过openid绑定手机号
     * @param phone
     * @param openid
     * @param avatarUrl
     * @param nickName
     * @param type
     * @return
     */
    @GetMapping("bindPhoneByOpenid")
    public ResHttp bindPhoneByOpenid(String phone,String openid,String avatarUrl,String nickName,
                                     String type,String lng,String lat,String scene){
        return loginService.bindPhoneByOpenid(phone,openid,avatarUrl,nickName,AppIdTypeEnum.valueOfCode(type),lng,lat,scene);
    }

    /**
     * 用户小程序端登录
     * @param jsCode
     * @param nickName
     * @param avatarUrl
     * @param type
     * @return
     */
    @GetMapping("doXcxLogin")
    public ResHttp doXcxLogin(String jsCode, String nickName, String avatarUrl, String type){
        return loginService.doXcxLogin(jsCode,nickName,avatarUrl,AppIdTypeEnum.valueOfCode(type));
    }





}
